package com.hxd.otc.module.wallet.presenter;

import android.support.annotation.NonNull;

import com.hxd.otc.base.BaseBean;
import com.hxd.otc.module.wallet.bean.PayOrderResultBean;
import com.hxd.otc.module.wallet.bean.WalletOrderInfoBean;
import com.hxd.otc.module.wallet.contract.AECPayCaptureContract;
import com.hxd.otc.module.wallet.model.PayModel;
import com.hxd.otc.module.wallet.model.WalletModel;
import com.hxd.otc.mvp.base.BasePresenter;
import com.hxd.otc.net.BaseObserver;

/**
 * Created by lzy on 2018/8/29 0029.
 * description ${AEC扫码支付Presenter}
 */
public class AECPayCapturePresenter extends BasePresenter<AECPayCaptureContract.IView> implements AECPayCaptureContract.IPresenter {

    private final PayModel mPayModel;
    private WalletModel mWalletModel;

    public AECPayCapturePresenter(AECPayCaptureContract.IView iView) {
        super(iView);
        mWalletModel = WalletModel.getInstance();
        mPayModel = PayModel.getInstance();
    }

    @Override
    public void getMerchantsOrderInfo(String id) {
        mWalletModel.getOrderInfo(id, new BaseObserver<WalletOrderInfoBean>() {
            @Override
            public void onNext(@NonNull String msg, @NonNull WalletOrderInfoBean walletOrderInfoBean) {
                mView.getMerchantsOrderInfoSuccess(walletOrderInfoBean);
            }

            @Override
            public void onError(int errType, @NonNull String errMessage) {
                mView.getMerchantsOrderInfoFail(errMessage);
            }
        }, mView.<BaseBean<WalletOrderInfoBean>>bindAutoDispose());
    }

    @Override
    public void innerQueryOrder(final String preId) {
        mPayModel.innerQueryOrder(preId, new BaseObserver<PayOrderResultBean>() {
            @Override
            public void onNext(@NonNull String msg, @NonNull PayOrderResultBean payOrderResultBean) {
                payOrderResultBean.setPreId(preId);
                mView.innerQueryOrderSuccess(payOrderResultBean);
            }

            @Override
            public void onError(int errType, @NonNull String errMessage) {
                mView.innerQueryOrderFail(errMessage);
            }
        }, mView.<BaseBean<PayOrderResultBean>>bindAutoDispose());
    }

    @Override
    public void start() {
    }
}
